import datetime
from haystack.indexes import RealTimeSearchIndex, CharField, BooleanField, DateField, FloatField
from haystack import site
from main.models import Excursion, Outcrop

"""
A search index to be used by the search engine.
""" 
class ExcursionIndex(RealTimeSearchIndex):
    text = CharField(document=True, use_template=True)
    name = CharField(model_attr='name')
    description = CharField(model_attr='description')
    public = BooleanField(model_attr='public')
    date = DateField(model_attr='date')
    
    def index_queryset(self):
        """Used when the entire index for model is updated."""
        return Excursion.objects.filter(date__lte=datetime.date.today())
    
"""
A search index to be used by the search engine.
""" 
class OutcropIndex(RealTimeSearchIndex):
    text = CharField(document=True, use_template=True)
    name = CharField(model_attr='name')
    description = CharField(model_attr='description')
    longitude = FloatField(model_attr='longitude')
    latitude = FloatField(model_attr='latitude')    
    
    def index_queryset(self):
        """Used when the entire index for model is updated."""
        return Outcrop.objects.all()

"""
registers the indexes so that they can be used by the search engine.
""" 
site.register(Excursion, ExcursionIndex)
site.register(Outcrop, OutcropIndex)